#!/usr/bin/env python
# encoding: utf-8

import sys

from util import fs

from kml_parser import Kml

kml_file = sys.argv[1] if len(sys.argv) > 1 else "./3feng.kml"
data = Kml(kml_file)
print(kml_file, len(data.points), data.cum_up, data.cum_down)

output  = data.points

ignores = list(range(0, 101, 5))
for ignore in ignores:
    up, _down, simple, removes = data.calc_cum_up_down(ignore)
    print(ignore, up, len(simple))
    for row, remove in zip(output, removes):
        row.append(remove[3])

fs.save_file(kml_file + ".csv", [
        ",".join(["time", "jingdu", "weidu", "latitude", *[f"ignore{ignore}m" for ignore in ignores], ]) + "\n",
    ] + [ ",".join([str(x) for x in row]) + "\n" for row in output])
